package com.business.web.spring;


import java.util.List;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.business.domain.T_product_spec_options;
//import com.business.mapper.T_product_spec_optionsMapper;
import com.business.service.T_product_spec_optionsService;

@Controller
@RequestMapping("/t_product_spec_options")

public class T_product_spec_optionsController
{
	private static Logger log = Logger.getLogger(T_product_spec_optionsController.class.getName());

	@Resource
    private T_product_spec_optionsService t_product_spec_optionsService;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	//@Resource
	//private T_product_spec_optionsMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_product_spec_options信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_product_spec_options")
	@ResponseBody
	public Pg getAllT_product_spec_options(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_product_spec_options t_product_spec_options = new T_product_spec_options();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("spec_id")!=null){
	        	t_product_spec_options.setSpec_id( BeanUtils.stringToInt("spec_id", request.getParameter("spec_id")));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_product_spec_options.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("spec_option_val")!=null&&!"".equals(request.getParameter("spec_option_val"))){
	        	t_product_spec_options.setSpec_option_val(request.getParameter("spec_option_val"));
	        }
			if(request.getParameter("status")!=null&&!"".equals(request.getParameter("status"))){
	        	t_product_spec_options.setStatus(request.getParameter("status"));
	        }
      	    if(request.getParameter("spec_option_id")!=null&&!"".equals(request.getParameter("spec_option_id"))){
	        	t_product_spec_options.setSpec_option_id(new Integer(request.getParameter("spec_option_id")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_product_spec_options.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_product_spec_options.setEnddate(request.getParameter("enddate"));
	        }
	        t_product_spec_options.setStartNo( startIndex );
	        t_product_spec_options.setPageSize( pageSize );
	        t_product_spec_options.setEndNo( pageSize );
	    	List<T_product_spec_options> findAll = t_product_spec_optionsService.findAll(t_product_spec_options);
	        int totalCount = t_product_spec_optionsService.findCountAll(t_product_spec_options);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_product_spec_optionsList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_product_spec_optionsList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_product_spec_options信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_product_spec_options")
	@ResponseBody
	public JsonVO saveT_product_spec_options(T_product_spec_options t_product_spec_options, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(t_product_spec_optionsService.save(t_product_spec_options)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3、修改T_product_spec_options信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_product_spec_options
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_product_spec_options")
	@ResponseBody
	public JsonVO updateT_product_spec_options(T_product_spec_options t_product_spec_options, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_product_spec_options t_product_spec_optionsTemp = t_product_spec_optionsService.findById(t_product_spec_options);
		//t_product_spec_optionsTemp.setXXX(t_product_spec_options.getXXX());
		//if(t_product_spec_optionsService.update(t_product_spec_optionsTemp)){

		if(t_product_spec_optionsService.update(t_product_spec_options)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 4、根据id查询T_product_spec_options单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_product_spec_options json格式字符串
	 */
	@RequestMapping("/getT_product_spec_options")
	@ResponseBody
	public T_product_spec_options getT_product_spec_options(Integer id,HttpServletRequest request){
		T_product_spec_options t_product_spec_options = new T_product_spec_options();
		t_product_spec_options.setSpec_option_id(id);
		return t_product_spec_optionsService.findById(t_product_spec_options);
	}

	/**
	 * 5、删除T_product_spec_options根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_product_spec_options")
	@ResponseBody
	public JsonVO delT_product_spec_options(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_product_spec_options t_product_spec_options = new T_product_spec_options();
		t_product_spec_options.setSpec_option_id(id);

		if(t_product_spec_optionsService.delete(t_product_spec_options)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_product_spec_options/toT_product_spec_optionsList查询所有数据页面
	 *  return /WEB-INF/views/business/t_product_spec_options/t_product_spec_optionsList.jsp
	 */
    @RequestMapping(value = "/toT_product_spec_optionsList")
    public String toT_product_spec_optionsList() {
    	log.debug("------跳转到/WEB-INF/views/business/t_product_spec_options/t_product_spec_optionsList.jsp------");
        return "business/t_product_spec_options/t_product_spec_optionsList";
    }

	/**
	 * 7、新增、修改、详情页面t_product_spec_options/toT_product_spec_optionsCurd跳转
     * business/t_product_spec_options/T_product_spec_optionsCurd.jsp
	 */
    @RequestMapping(value = "/toT_product_spec_optionsCurd")
    public String toT_product_spec_optionsCurd() {
    	log.debug("------跳转到/WEB-INF/views/business/t_product_spec_options/t_product_spec_optionsCurd.jsp------");
        return "business/t_product_spec_options/t_product_spec_optionsCurd";
    }

    /**
	 * 8、批量删除T_product_spec_options根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_product_spec_optionsBatch")
	public String delT_product_spec_optionsBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_product_spec_options t_product_spec_options = new T_product_spec_options();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_product_spec_options.setSpec_option_id(new Integer(ids[i]).intValue());
			t_product_spec_optionsService.delete(t_product_spec_options);
		}
		if(j==ids.length){
			log.debug("------t_product_spec_options批量删除成功！------");
		}else{
			log.error("------t_product_spec_options批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_product_spec_options/getAllT_product_spec_options";
	}
*/



}









